package com.pjbao.app.targetSale.userInfo;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by 邱鹏 on 2016/10/11.
 */
@RestController
@RequestMapping("/app/targetSale/userInfo")
public class UserInfoController {
    @Autowired
    UserInfoDao dao;
    ObjectMapper mapper=new ObjectMapper();
    @RequestMapping("/userInfoList")
    public String userInfoList(UserInfo userInfo,int offset, int limit) throws JsonProcessingException {
        PageRequest pageable = new PageRequest(offset/limit, limit);
        String result=null;
        Page<UserInfo> page=  dao.findAll(pageable);
        Map map=new HashMap();
        map.put("total",page.getTotalElements());
        map.put("rows",page.getContent());
        result=mapper.writeValueAsString(map);
        return result;
    }
}
